package com.example.ttt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.swing.*;
import java.awt.*;

@Component
public class StartMain {

    @Autowired
    private GUIInterface guiInterface;

    private JFrame jFrame = new JFrame("TTT");

    public void start(){

        // 允许设置给jframe设置皮肤
        jFrame.setDefaultLookAndFeelDecorated(true);
        try {
            UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedLookAndFeelException e) {
            throw new RuntimeException(e);
        }

        // 绘制主界面
        guiInterface.interfaceGui(jFrame);

        // 设置主界面的属性
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    /*
                    * 窗口可见      setVisible
                    * 窗口居中显示    setLocationRelativeTo
                    * 窗口不能被放大   setResizable
                    * */
                    jFrame.setVisible(true);
                    jFrame.setLocationRelativeTo(null);
                    jFrame.setResizable(false);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        System.out.println("OK");
    }
}
